package com.study.www.config;

import lombok.Data;

import java.io.Serializable;

/**
 * 回参
 * @author : 89007337.zhuyanpeng
 * @Description: :
 * @date :Create in  2019/6/27- 21:32
 * @Version: V1.0
 * @Modified By:
 **/
@Data
public class Result<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;
    private Long timestamp;

    public Result() {
    }

    public Result(T data) {
        this.data = data;
    }

    public static <T> Result<T> success(){
        return success(null,"");
    }


    public static <T> Result<T> success(T data){
        return success(data,"");
    }

    public static <T> Result<T> success(T data,String msg){
        Result<T> result = new Result<T>();
        result.setCode(200);
        result.setMsg(msg);
        result.setData(data);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }



    public static <T> Result<T> error(Integer code, String msg){
        Result result = new Result<T>();
        result.setCode(code);
        result.setMsg(msg);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }
    public static <T> Result<T> error(String msg){
        return error(500,msg);
    }

    /**
     * 未知错误和不可能请求到的错误
     * @return
     */
    public static <T>  Result<T> error(){
        return error("服务异常");
    }


}
